#!/bin/sh

. /lib/functions.sh
. /lib/functions/system.sh

#等待br-lan准备好
while [ ! -d /sys/class/net/br-lan ]
do
    sleep 5
    logger -t Wifi -p daemon.info  wait for br-lan!
done

#MAC地址
Mac=`cat /sys/class/net/br-lan/address | sed  's/://g' | tr a-z A-Z`

default_wifi_ap() {
	uci -q batch <<-EOF
	delete wireless.@wifi-iface[-1]
	set wireless.WifiAp=wifi-iface
	set wireless.WifiAp.device='radio0'
	set wireless.WifiAp.mode='ap'
	set wireless.WifiAp.ssid="CoreBoard-$Mac"
	set wireless.WifiAp.key="CoreBoardWifiAp"
	set wireless.WifiAp.network="lan"
	set wireless.WifiAp.encryption="psk-mixed"
	set wireless.radio0.disabled=0
	commit
	EOF
}
#加载wireless配置
config_load wireless

#默认wifi_ap
default_wifi_ap

#启动wifi
wifi
